using System;
using Unity.VisualScripting;
using UnityEngine;
using UnityGameFramework.Runtime;

namespace LS.UGFUnits
{
    [UnitCategory("Unity Game Framework")]
    public abstract class FrameworkComponentInvokeUnit<TComponent> : InvokeMemberBase, IFrameworkComponentUnit<TComponent> where TComponent : GameFrameworkComponent
    {
        private Member m_Member;
        
        [DoNotSerialize]
        public abstract string FunctionName { get; }
        
        [DoNotSerialize]
        public abstract Type[] ParameterTypes { get; }
        
        [DoNotSerialize]
        public abstract TComponent Target { get; }
        
        [DoNotSerialize]
        public override Member member => m_Member;
        
        [DoNotSerialize]
        public override bool requiresTarget => false;

        [DoNotSerialize]
        public override object targetObject => Target;

        public void CheckFrameworkAvailable()
        {
            if (!FrameworkObserver.GFAvailable)
            {
                Debug.LogError("Unity Game Framework is not available!");
            }
        }

        public FrameworkComponentInvokeUnit(): base()
        {
            m_Member = new Member(typeof(TComponent), FunctionName, ParameterTypes);
        }
    }
}